const express = require('express')
const moment = require('moment')
const app = express()
const port = 3000
const path = require('path')
const fs = require('fs')

app.get('/', (req, res) => {

  let time = moment().format("YYYY-MM-DD HH:mm:ss");

  let ip = req.ip

  let method = req.method

  let userAgent = req.headers["user-agent"]

  let str = `${time}-${ip}-${method}-${userAgent}\n`

  console.log(str)

  let filename = path.join(__dirname, 'logs', moment().format("YYYYMMDD") + ".txt");

  console.log(filename)

  res.send('hello world')

  fs.appendFile(filename, str, err => {
    console.log(err)
  })

})

app.use(express.static('rm'))
app.listen(port, () => {
  console.log('example app listening on port http://127.0.0.1:3000')
})